package com.zoe.thread.th14_volatile测试;

/**
 * @Author Zoe
 * @Date: 2021/05/07
 * @Description 禁止指令重排 https://www.cnblogs.com/xinde123/p/7602583.html
 */
public class VolatileStop {

    int a = 0;
    // 在flag加上volatile可以保证之前的变量不会发生指令重排序
    volatile boolean flag = false;

    public void method01() {
        a = 1;
        flag = true;
        System.out.println(a +"===="+ flag);
    }


    public void method02() {
        if (flag) {
            a = a + 5;
            System.out.println(a);
        }

    }

}
